var sx=pre_x
var sy=pre_y
var i=0,nx,ny;
global.bin=-1;
var dx,dy,rx,ry;

rx=x-sx;
ry=y-sy;
alpha=arctan2(ry,rx);

var dist;
dist=sqrt(rx*rx+ry*ry);

dx=cos(alpha);
dy=sin(alpha);

while (global.bin<0)
{
global.xx=sx+i*dx;
global.yy=sy+i*dy;
//show_message("start coords "+string(sx)+" "+string(sy)+" delta coords "+string(rx)+" "+string(ry)+" dx dy = "+string(dx)+" "+string(dy));
with (player)
{
global.bin=instance_place(global.xx,global.yy,obstacle);
}
for (z=0;z<instance_number(fence);z++)
{
inst=instance_find(fence,z);
dummy.x=global.xx;
dummy.y=global.yy;
if collision_line(inst.x1,inst.y1,inst.x2,inst.y2,dummy,true,true) 
{
global.bin=1;


}
}
if ((global.xx<play_map.x1+player.sprite_width/2)||(global.xx>play_map.x2-player.sprite_width/2)||(global.yy<play_map.y1+player.sprite_width/2)||(global.yy>play_map.y2-player.sprite_width/2)) global.bin=1;

ddi=i*sqrt(dx*dx+dy*dy);
if (koef*(ddi/player.run_speed)>10-global.secs) global.bin=1;
if (ddi>=dist) exit;
i++

}
x=sx+dx*(i-2);
y=sy+dy*(i-2);

